﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using ArrayConsoleRender;

namespace DrawArray
{
    class Program
    {
        public static void Main(string[] args)
        {
            int howMatch = 100;
            ConsolePainter.PrepareScren();
            int[] arr = new int[howMatch];
            CreateArray(howMatch,arr);
            int max = FindMax(arr);
            SortArr(arr);
            ConsolePainter.DrawArray(arr, max);
            Console.ReadKey();
        }
        public static void SortArr(int[] arr)
        {
            int lenght = arr.Length;
            int max = FindMax(arr);
            for (int i = 0; i < lenght-1;i++ )
            {
                for (int j = 0; j < lenght-1;j++ )
                {
                    if(arr[j]>arr[j+1]) 
                    {
                        SwapMembers(arr, j, j + 1);
                    }
                }          
                ConsolePainter.DrawArray(arr, max);
                Thread.Sleep(1);
                Console.Clear();
            }
        }
        public static void SwapMembers(int[] arr, int a, int b)
        {
            int temp = arr[a];
            arr[a] = arr[b];
            arr[b] = temp;

        }
        public static void CreateArray(int howMatch, int[] arr)
        {
            Random R = new Random(int.MaxValue);
            
            for (int i = 0; i < howMatch;i++ )
            {
                int randomNumber = R.Next(0, 60);
                arr[i] = randomNumber;
            }
        }
        public static int FindMax(int[] arr)
        {
            int max = 0;
            int lenght=arr.Length;
            for (int i = 0; i < lenght; i++)
            {
                if (arr[i] > max) max = arr[i];
            }
            return max;
        }
    }
}
